﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Threading.Tasks;
using System.Web.Mvc;
using ZFine.Application.Project;
using ZFine.Code;
using ZFine.Domain.Entity;
using System.Linq;
using System.Web;
using ZFine.Application.SystemManage;
using ZFine.Web;

namespace Logiv.WEB.Areas.Project.Controllers
{
    /// <summary>
    /// 操作指南与合作申请
    /// </summary>
    public class InstructionsController : BaseController
    {
        private InstructionsApp serviceapp = new InstructionsApp();

        public override ActionResult Details()
        {
            var keyValue = Request.QueryString["keyValue"];
            var data = serviceapp.GetForm(keyValue);
            if (data != null)
            {
                ViewData["objs"] = data;
            }
            else
            {
                ViewData["objs"] = null;
            }
            return View();
        }

        #region 操作-查询提交
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJsonC(Pagination pagination, string keyword)
        {
            try
            {
                var data = new
                {
                    rows = serviceapp.GetListC(pagination, keyword),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());

            }
            catch (Exception ex)
            {
                return null;
            }
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateInput(false)]
        public ActionResult SubmitFormC(InstructionsEntity ServiceEntity, string keyValue)
        {
            int result = serviceapp.SubmitFormC(ServiceEntity, keyValue);

            if (result == -1)
            {
                return Error("存在相同的名称");
            }
            else if (result == -2)
            {
                return Error("超出了添加的个数");
            }
            else
            {
                return Success("操作成功。");
            }
        }
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJsonC(string keyValue)
        {
            var data = serviceapp.GetForm(keyValue);
            if (data == null)
            {
                data = serviceapp.getdefaultobj(f => f.State == true && f.Type == 1);
                if (data != null)
                {
                    Content(data.ToJson());
                }
            }
            return Content(data.ToJson());
        }
        #endregion 

        #region 申请-查询提交
        public ActionResult Index1()
        {
            return View();
        }
        public  ActionResult Form1()
        {
            return View();
        }
        public ActionResult Details1()
        {
            var keyValue = Request.QueryString["keyValue"];
            var data = serviceapp.GetForm(keyValue);
            if (data != null)
            {
                ViewData["objs"] = data;
            }
            else
            {
                ViewData["objs"] = null;
            }
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJsonH(Pagination pagination, string keyword)
        {
            try
            {
                var data = new
                {
                    rows = serviceapp.GetListH(pagination, keyword),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());

            }
            catch (Exception ex)
            {
                return null;
            }
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateInput(false)]
        public ActionResult SubmitFormH(InstructionsEntity ServiceEntity, string keyValue)
        {
            int result = serviceapp.SubmitFormH(ServiceEntity, keyValue);

            if (result == -1)
            {
                return Error("存在相同的名称");
            }
            else if (result == -2)
            {
                return Error("超出了添加的个数");
            }
            else
            {
                return Success("操作成功。");
            }
        }
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJsonH(string keyValue)
        {
            var data = serviceapp.GetForm(keyValue);
            if (data == null)
            {
                data = serviceapp.getdefaultobj(f => f.State == true && f.Type == 2);
                if (data != null)
                {
                    Content(data.ToJson());
                }
            }
            return Content(data.ToJson());
        }




        #endregion
    }
}
